package cn.onein.edu.web.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import org.springframework.stereotype.Service;

import cn.onein.edu.biz.bean.Item;
import cn.onein.edu.biz.bean.Order;
import cn.onein.edu.biz.bean.Product;

@Service
public class PaymentDao {

	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;
	
	public Product getProductById(Long id){
		return (Product)sqlMapClientTemplate.queryForObject("selectProductById", id);
	}
	
	public void insertOrder(Order order){
		sqlMapClientTemplate.insert("insertOrder", order);
	}
	
	public void insertItem(Item item){
		sqlMapClientTemplate.insert("insertItem", item);
	}
	
	public Order getOrderByOrderNo(String orderNo){
		return (Order)sqlMapClientTemplate.queryForObject("getOrderByOrderNo", orderNo);
	}
	
	@SuppressWarnings("unchecked")
	public List<Order> getOrderByUserId(Long userId){
		return (List<Order>)sqlMapClientTemplate.queryForList("getOrderByUserId", userId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Item> getItemByOrderId(Long orderId){
		return (List<Item>)sqlMapClientTemplate.queryForList("getItemByOrderId",orderId);
	}
	
	@SuppressWarnings("unchecked")
	public List<Product> getProductByType(Integer type){
		return (List<Product>)sqlMapClientTemplate.queryForList("getProductByType",type);
	}
	
	public void updateOrderStatusByOrderNo(Map<String,Object> param){
		sqlMapClientTemplate.update("updateOrderByOrderNo", param);
	}
	
	public Order getLastOrderByUserId(Long userId){
		return (Order)sqlMapClientTemplate.queryForObject("getLastOrderByUserId",userId);
	}
	
	public void orderSuccessByOrderNo(Map<String,Object> param){
		sqlMapClientTemplate.update("orderSuccessByOrderNo", param);
	}
	
	public void updateOrderPaymentTypeByOrderNo(Map<String,Object> param){
		sqlMapClientTemplate.update("updateOrderPaymentTypeByOrderNo", param);
	}
}
